import java.util.Random;

class Perseus {
   private native long perseusAlloc();
   private native int perseusInit(long a, float A1, float A2, float A3, float A4);
   private native char [] perseusCode(long a, char[] msg);
   private native char [] perseusDecode(long a, char[] msg);
   private native void perseusDestroy( long a );
   
   static {
      System.loadLibrary("perseus-jni");
   }

   public long peer;

   public Perseus() {
      Random r = new Random();

      this.peer = perseusAlloc();
      perseusInit( peer, r.nextFloat(), r.nextFloat(), r.nextFloat(), r.nextFloat() );
   }

   public Perseus(float a1, float a2, float a3, float a4) {
      Random r = new Random();

      this.peer = perseusAlloc();
      perseusInit( peer, a1, a2, a3, a4 );
   }

   public String Code(String msg) {
      char[] encoded_data = perseusCode( this.peer, msg.toCharArray() );

      return new String( encoded_data );
   }

   public String Decode(String msg) {
      char[] decoded_data = perseusDecode( this.peer, msg.toCharArray() );

      return new String( decoded_data );
   }

   public void finalize() {
      perseusDestroy( this.peer );
   }
}
